/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.examination.barbecue.record.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.examination.barbecue.record.entity.TexaminationBarbecueRecord;
import com.jeesite.modules.zx.examination.barbecue.record.service.TexaminationBarbecueRecordService;

/**
 * 理论考试记录Controller
 * @author zpp
 * @version 2020-02-12
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/examination/barbecue/record/texaminationBarbecueRecord")
public class TexaminationBarbecueRecordController extends BaseController {

	@Autowired
	private TexaminationBarbecueRecordService texaminationBarbecueRecordService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TexaminationBarbecueRecord get(String id, boolean isNewRecord) {
		return texaminationBarbecueRecordService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:examination:barbecue:record:texaminationBarbecueRecord:view")
	@RequestMapping(value = {"list", ""})
	public String list(TexaminationBarbecueRecord texaminationBarbecueRecord, Model model) {
		model.addAttribute("texaminationBarbecueRecord", texaminationBarbecueRecord);
		return "modules/zx/examination/barbecue/record/texaminationBarbecueRecordList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:examination:barbecue:record:texaminationBarbecueRecord:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TexaminationBarbecueRecord> listData(TexaminationBarbecueRecord texaminationBarbecueRecord, HttpServletRequest request, HttpServletResponse response) {
		texaminationBarbecueRecord.setPage(new Page<>(request, response));
		Page<TexaminationBarbecueRecord> page = texaminationBarbecueRecordService.findPage(texaminationBarbecueRecord);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:examination:barbecue:record:texaminationBarbecueRecord:view")
	@RequestMapping(value = "form")
	public String form(TexaminationBarbecueRecord texaminationBarbecueRecord, Model model) {
		model.addAttribute("texaminationBarbecueRecord", texaminationBarbecueRecord);
		return "modules/zx/examination/barbecue/record/texaminationBarbecueRecordForm";
	}

	/**
	 * 保存理论考试记录
	 */
	@RequiresPermissions("zx:examination:barbecue:record:texaminationBarbecueRecord:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TexaminationBarbecueRecord texaminationBarbecueRecord) {
		texaminationBarbecueRecordService.save(texaminationBarbecueRecord);
		return renderResult(Global.TRUE, text("保存理论考试记录成功！"));
	}
	
	/**
	 * 停用理论考试记录
	 */
	@RequiresPermissions("zx:examination:barbecue:record:texaminationBarbecueRecord:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TexaminationBarbecueRecord texaminationBarbecueRecord) {
		texaminationBarbecueRecord.setStatus(TexaminationBarbecueRecord.STATUS_DISABLE);
		texaminationBarbecueRecordService.updateStatus(texaminationBarbecueRecord);
		return renderResult(Global.TRUE, text("停用理论考试记录成功"));
	}
	
	/**
	 * 启用理论考试记录
	 */
	@RequiresPermissions("zx:examination:barbecue:record:texaminationBarbecueRecord:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TexaminationBarbecueRecord texaminationBarbecueRecord) {
		texaminationBarbecueRecord.setStatus(TexaminationBarbecueRecord.STATUS_NORMAL);
		texaminationBarbecueRecordService.updateStatus(texaminationBarbecueRecord);
		return renderResult(Global.TRUE, text("启用理论考试记录成功"));
	}
	
	/**
	 * 删除理论考试记录
	 */
	@RequiresPermissions("zx:examination:barbecue:record:texaminationBarbecueRecord:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TexaminationBarbecueRecord texaminationBarbecueRecord) {
		texaminationBarbecueRecordService.delete(texaminationBarbecueRecord);
		return renderResult(Global.TRUE, text("删除理论考试记录成功！"));
	}
	
}